﻿(() => {
    const setCookie = (key, value, days) => {
        // 对值进行 URL 编码
        const encodedValue = encodeURIComponent(value);

        let expires = "";
        if (days) {
            const date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            expires = "; expires=" + date.toUTCString();
        }

        document.cookie = key + "=" + encodedValue + expires + "; path=/";
    };

    const getCookie = (key) => {
        const value = `; ${document.cookie}`;
        const parts = value.split(`; ${key}=`);
        if (parts.length === 2) return decodeURIComponent(parts.pop().split(';').shift());
    };

    // 获取查询参数
    const getQuery = (paramName) => {
        const url = new URL(window.location.href);
        return url.searchParams.get(paramName);
    }
})